package com.yyx.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyx.server.pojo.MenuRole;
import com.yyx.server.mapper.MenuRoleMapper;
import com.yyx.server.service.MenuRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyx.server.vo.ResultVo;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YongXin
 * @since 2021-07-24
 */
@Service
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleMapper, MenuRole> implements MenuRoleService {

    @Autowired
    private MenuRoleMapper menuRoleMapper;
    /**
     * 更新角色菜单
     * @param rid 角色id
     * @param mids 菜单id
     * @return
     */
    @Override
    @Transactional
    public ResultVo updMenuRole(Integer rid, Integer[] mids) {
        menuRoleMapper.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        if (mids==null||mids.length==0){
            return ResultVo.success("修改成功");
        }
        Integer insertRecord = menuRoleMapper.insertRecord(rid, mids);
        if (insertRecord==mids.length){
            return ResultVo.success("修改成功");
        }
        return ResultVo.error("修改失败");
    }
}
